# 定义点击器类，不指定外部命名空间参数，使用类内部定义
Add-Type @"
using System;
using System.Runtime.InteropServices;

namespace Win32 {
    public class Clicker {
        [DllImport("user32.dll")]
        public static extern bool SetCursorPos(int X, int Y);
        
        [DllImport("user32.dll")]
        public static extern void mouse_event(uint flags, uint dx, uint dy, uint data, UIntPtr info);
        
        public const uint MOUSEEVENTF_LEFTDOWN = 0x0002;
        public const uint MOUSEEVENTF_LEFTUP = 0x0004;
    }
}
"@

Add-Type -AssemblyName System.Windows.Forms

$w = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Width
$h = [System.Windows.Forms.SystemInformation]::PrimaryMonitorSize.Height

$x = [int]($w * 0.645)
$x2 = [int]($w * 0.520)
$y = [int]($h * 0.862)

Write-Host "Starting click at ($x,$y) - every 3 seconds"

while ($true) {
    [Win32.Clicker]::SetCursorPos($x, $y)
    

    [Win32.Clicker]::mouse_event([Win32.Clicker]::MOUSEEVENTF_LEFTDOWN, 0, 0, 0, [UIntPtr]::Zero)
    [Win32.Clicker]::mouse_event([Win32.Clicker]::MOUSEEVENTF_LEFTUP, 0, 0, 0, [UIntPtr]::Zero)

    [Win32.Clicker]::SetCursorPos($x2, $y)
    [Win32.Clicker]::mouse_event([Win32.Clicker]::MOUSEEVENTF_LEFTDOWN, 0, 0, 0, [UIntPtr]::Zero)
    [Win32.Clicker]::mouse_event([Win32.Clicker]::MOUSEEVENTF_LEFTUP, 0, 0, 0, [UIntPtr]::Zero)
    [Win32.Clicker]::SetCursorPos($x, $y)

    Write-Host "Click success"
    Start-Sleep -s 3
}
